package net.keebook.webapp.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import net.keebook.webapp.dao.UserDao;
import net.keebook.webapp.entity.GeneratorPreferences;
import net.keebook.webapp.model.SessionModel;


@ManagedBean
@RequestScoped
public class GeneratorBean {
	private Integer length = 16;
	private Boolean upperCase = true;
	private Boolean lowerCase = true;
	private Boolean digits = true;
	private Boolean minus = false;
	private Boolean underline = false;
	private Boolean space = false;
	private Boolean special = false;
	private Boolean brackets = false;
	private Boolean highAnsi = false;
	
	@Inject
	private UserDao userDao;
	private SessionModel sessionModel;
	
	
	@PostConstruct
	public void init() {
		setSessionModel(SessionModel.getInstance(FacesContext.getCurrentInstance()));
		
		GeneratorPreferences preferences = userDao.get(getSessionModel().getUserId()).getGeneratorPreferences();
		if (preferences != null) {
			setLength(preferences.getLength());
			setUpperCase(preferences.getUpperCase());
			setLowerCase(preferences.getLowerCase());
			setDigits(preferences.getDigits());
			setMinus(preferences.getMinus());
			setUnderline(preferences.getUnderline());
			setSpace(preferences.getSpace());
			setSpecial(preferences.getSpecial());
			setBrackets(preferences.getBrackets());
			setHighAnsi(preferences.getHighAnsi());
		}
	}
	
	public Integer getLength() {
		return length;
	}
	public void setLength(Integer length) {
		this.length = length;
	}
	public Boolean getUpperCase() {
		return upperCase;
	}
	public void setUpperCase(Boolean upperCase) {
		this.upperCase = upperCase;
	}
	public Boolean getLowerCase() {
		return lowerCase;
	}
	public void setLowerCase(Boolean lowerCase) {
		this.lowerCase = lowerCase;
	}
	public Boolean getDigits() {
		return digits;
	}
	public void setDigits(Boolean digits) {
		this.digits = digits;
	}
	public Boolean getMinus() {
		return minus;
	}
	public void setMinus(Boolean minus) {
		this.minus = minus;
	}
	public Boolean getUnderline() {
		return underline;
	}
	public void setUnderline(Boolean underline) {
		this.underline = underline;
	}
	public Boolean getSpace() {
		return space;
	}
	public void setSpace(Boolean space) {
		this.space = space;
	}
	public Boolean getSpecial() {
		return special;
	}
	public void setSpecial(Boolean special) {
		this.special = special;
	}
	public Boolean getBrackets() {
		return brackets;
	}
	public void setBrackets(Boolean brackets) {
		this.brackets = brackets;
	}
	public Boolean getHighAnsi() {
		return highAnsi;
	}
	public void setHighAnsi(Boolean highAnsi) {
		this.highAnsi = highAnsi;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public SessionModel getSessionModel() {
		return sessionModel;
	}

	public void setSessionModel(SessionModel sessionModel) {
		this.sessionModel = sessionModel;
	}
}
